import 'package:flutter/cupertino.dart';
import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';

class BottomInputWidget extends StatelessWidget {
  final String title;
  final String hint;
  final String btnText;
  final Function(String str)? onSubmit;
  final CommonInputType keyboard;

  String content = "";

  BottomInputWidget(
      {this.title = "请输入",
      this.hint = "请输入",
      this.btnText = "确定",
      this.onSubmit,this.content = "",this.keyboard = CommonInputType.multiline});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        CommonText(title, fontWeight: FontWeight.w600, textSize: 20),
        Container(
          height: 10,
        ),
        CommonInput(
          text: content,
          hintText: hint,
          onChanged: (str) {
            content = str;
          },
          isDense: true,
          keyboardType: keyboard,
          border: InputBorder.none,
          padding: EdgeInsets.zero,
          maxLines: 5,
        ).addToContainer(
          decoration: BoxDecoration(color: Colors.grey[200],borderRadius: 6.borderRadius),
          padding: EdgeInsets.all(8)
        ),
        Container(height: 16,),
        ElevatedButton(onPressed: (){
         if(onSubmit!=null){
           Navigator.pop(context);
           onSubmit!(content);

         }
        }, child: CommonText(btnText,textColor: Colors.white),style: ButtonStyle(
          elevation: WidgetStateProperty.all(0),
          shape: WidgetStateProperty.all(StadiumBorder()),
          minimumSize: WidgetStateProperty.all(Size(double.infinity,45))
        ),)
      ],
    ).addToContainer(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius:
                BorderRadius.only(topRight: 10.radius, topLeft: 10.radius)),
        padding: EdgeInsets.all(16));
  }
}

void showBottomInput(
    BuildContext context,
    {String title = "请输入",
    String hint = "请输入",
    String btnText = "确定",
      String content = "",
      CommonInputType keyboard = CommonInputType.multiline,
    Function(String str)? onSubmit}) {
  showModalBottomSheet(context: context, builder: (context){
    return SingleChildScrollView(
      child: BottomInputWidget(title: title,hint: hint,btnText: btnText,onSubmit: onSubmit,content: content,keyboard: keyboard,),
      padding: EdgeInsets.only(
          bottom: MediaQuery.of(context).viewInsets.bottom),
    );
  },backgroundColor: Colors.transparent,isScrollControlled: true);
}
